package main

import (
	"fmt"
	"time"
)

func main() {
	sign := make(chan struct{}, 10)
	var count int
	for i := 0; i < 10; i++ {
		go func(i int) {
			for {
				if count == i{
					fmt.Println(i)
					count ++
					sign <- struct{}{}
					break
				}
				time.Sleep(time.Nanosecond)
			}
		}(i)
	}
	for j := 0; j < 10; j++ {
		<- sign
	}
}